-- card: 2821 from stack: in -- bmap block id: 5666 -- flags: 0000 -- background id: 2774 -- name: Computer Card ----- HyperTalk script ----- -- -- -- This stack and it's scripts and graphics are copyright 1989, -- Prophecy Software Inc. All rights reserved. -- -- You may examine this code for your own benifit. -- If you wish to make changes that enhance the stack please make -- them to a copy and contact us at: -- -- Prophecy Software Inc. -- 3650 Silverside Rd. Suite 3 -- Wilmington, DE 19810 -- (302) 994-1502 -- -- We will be happy to consider distributing an updated version with -- propper credit given to the author. distribution of copies of this -- stack with un-authorized alterations constitures copyright -- violation and fraud. on com_turn global cbs, cca, ctt, csu, cpt, chit_count global results, ship_up, game_active, opponent put card field "data" of card "computer card" into the_message put "" into card field "data" of card "computer card" put word 1 of the_message into command -- message from player if command is "sm" then get number of lines in card field "lines" of card "computer card" get random(it) get line it of card field "lines" of card "computer card" get csend("sm" && it && "•") exit com_turn end if -- only messages are active after the game is over. if game_active is false then exit com_turn -- move, query to ship at this location if command is "move" then put word 2 of the_message into value get field value of card "computer card" put it into out_value if opponent is "CVSC" then put "Incoming..." into card field 1 of card "enemy board" put word 2 of the_message into value if it is not "" then push this card go to card "player Card" play boom set icon of button value to 7009 get flash ("Hit...") else push this card go to card "player Card" play splash set icon of button value to 19123 get flash("Miss...") end if end if get csend ("re" && value && out_value && "•") exit com_turn end if -- results, answer to a move query if command is "re" then put word 2 of the_message into value put word 3 of the_message into shot if opponent is "CVSC" then push this card go to card "enemy board" if shot is not "•" then put "Tower Reports Hit.." into card field 1 of card "enemy board" play boom set icon of button value of card "enemy board" to 7009 else put "Tower Reports Miss.." into card field 1 of card "enemy board" play splash set icon of button value of card "enemy board" to 19123 end if pop card end if if shot is not "•" then put shot && value into results if shot is "B" then add 1 to cbs if cbs is 5 then put done_test("B") into ship_up put "" into results end if end if if shot is "C" then add 1 to cca if cca is 4 then put done_test("C") into ship_up put "" into results end if end if if shot is "T" then add 1 to ctt if ctt is 3 then put done_test("T") into ship_up put "" into results end if end if if shot is "S" then add 1 to csu if csu is 3 then put done_test("S") into ship_up put "" into results end if end if if shot is "P" then add 1 to cpt if cpt is 2 then put done_test("P") into ship_up put "" into results end if end if add 1 to chit_count if chit_count is 17 then get csend("win" && "•") put false into game_active send idle to stack repeat with count = 1 to 64 get field count of card "computer card" if it is not empty then get csend("at" && count && "•") send idle to stack end if end repeat exit com_turn end if else put "" into results get csend ("go" && "•") exit com_turn end if if command is "go" then send find_move to card "computer card" exit com_turn end if -- start determine who goes first if command is "st" then put word 2 of the_message into value if random(10) < value then get csend("go" && "•") -- other player goes first else get send_message("go" && "•") end if exit com_turn end if if command is "win" then put false into game_active exit com_turn end if if command is "done" then exit com_turn end if -- unknown command, send query end com_turn function csend the_message global opponent if opponent is "CVSC" then get writemodem(the_message) exit csend end if put the_message into card field "message" of card "computer card" return 0 end csend on find_move global results, ship_up, where_at_now, direction global pattern, active_ship, opponent -- pattern is a counter 1 to 64 looping that describes the -- firing pattern of the computer -- results is the results of our last shot -- where at now is the location of where we last hit -- active ship is what type of ship are we shelling. put word 1 of results into the_ship put word 2 of results into where -- are we already shelling a ship? if ship_up is true then -- if we hit something, then that becomes our last hit -- position and we look for a spot from there. if results is not empty then -- last shot was a hit, update location to reflect where -- hit was. add direction to where_at_now -- if we have hit a new ship, then record it. -- and start fresh shelling this ship. -- we will return after it is sunk. -- sort of a filo stack for ships. if active_ship is not the_ship then put results && direction & numtochar(13) after card field "active" in card "computer card" put the_ship into active_ship put 1 into direction else put " " & direction into word 4 of last line of card field "Active" in card "computer card" end if else -- we missed this time, but we have hit a ship, so -- let's see if we have established it's direction yet -- (word 4 of field active) if so, then lets take the -- initial hit location and reverse gears. get last line of card field active of card "computer card" if it is not empty then if word 4 of it is not empty then put word 2 of it into move put move into where_at_now put word 4 of it into direction put -1 * direction into direction add direction to move end if end if end if else -- test for first hit on ship, record it if it is. if results is not empty then put true into ship_up put where into where_at_now put 1 into direction put results && "1" & numtochar(13) after card field "active" in card "computer card" put the_ship into active_ship end if end if -- all right, we seem to think we need to find a new ship, -- but first, lets just see... if ship_up is false then put done_test("") into ship_up end if if ship_up is true then put xxx() into move if move is not -1 then get csend("move" && move && "•") exit find_move end if end if -- here we are continuing the shelling pattern -- which means we don't know where a ship is! put false into ok put false into ship_up put 1 into direction repeat until ok add 1 to pattern if pattern is 65 then put 1 into pattern put line pattern of card field "Pattern" of card "computer card" into move get icon of button move of card "Player Card" if opponent is "CVSC" then get icon of button move of card "Enemy Board" end if if it is 0 then put true into ok end repeat get csend("move" && move && "•") end find_move function xxx global results, ship_up, where_at_now, direction, opponent put false into ok put -1 into move repeat until ok put where_at_now + direction into test if test < 1 or test > 64 then get new_direction() else get icon of button test of card "player card" if opponent is "CVSC" then get icon of button test of card "Enemy Board" end if if it is 0 then put test into move put true into ok else get new_direction() end if -- test to make sure we do not circle forever. -- at this point, we may have reversed direction on the ship -- give one test at the negative direction of the last ship -- in the active list, note, must have 4 words, meaning -- that we have a known direction of the ship -- this condition occures when we walk to one end of a ship -- and all the spaces around it are already shelled. if direction is 1 and move is -1 then get last line of card field active of card "computer card" if it is not empty then if word 4 of it is not empty then put word 2 of it into move put move into where_at_now put word 4 of it into direction put -1 * direction into direction add direction to move end if end if put true into ok end if end if end repeat return move end xxx function new_direction global direction if direction is 1 then put 8 into direction return 1 end if if direction is 8 then put -1 into direction return 1 end if if direction is -1 then put -8 into direction return 1 end if if direction is -8 then put 1 into direction return 1 end if end new_direction on setup put "Clearing..." into card field status repeat with count = 1 to 64 put "" into field count end repeat put false into ok put "Battle Ship" && numtochar(13) into card field status repeat until ok is true put random(8) into h put random(8) into v put random(2) into angle put put_ship(angle, 5, h, v, "B") into ok end repeat put false into ok put "Carrier" & numtochar(13) after card field status repeat until ok is true put random(8) into h put random(8) into v put random(2) into angle put put_ship(angle, 4, h, v, "C") into ok end repeat put false into ok put "Transport" & numtochar(13) after card field status repeat until ok is true put random(8) into h put random(8) into v put random(2) into angle put put_ship(angle, 3, h, v, "T") into ok end repeat put false into ok put "Submarine" & numtochar(13) after card field status repeat until ok is true put random(8) into h put random(8) into v put random(2) into angle put put_ship(angle, 3, h, v, "S") into ok end repeat put false into ok put "PT Boat" & numtochar(13) after card field status repeat until ok is true put random(8) into h put random(8) into v put random(2) into angle put put_ship(angle, 2, h, v, "P") into ok end repeat end setup function put_ship angle, length, h, v, letter if angle is 1 then if h + length - 1 > 8 then return false exit put_ship end if else if v + length - 1 > 8 then return false exit put_ship end if end if put (v - 1) * 8 + h into the_field put the_field into temp_field repeat with count = 1 to length get field temp_field if it is not "" and it is not letter then return false exit put_ship end if if angle is 1 then add 1 to temp_field else add 8 to temp_field end if end repeat put the_field into temp_field repeat with count = 1 to length put letter into field temp_field if angle is 1 then add 1 to temp_field else add 8 to temp_field end if end repeat return true end put_ship function done_test the_letter global results, ship_up, where_at_now, direction, active_ship global opponent -- remove the ship sunk from the active roster, and -- return true if there are no other known unsunk ships -- if there are other unsunk ships then it is because we -- walked from one ship to another while shelling the first. -- we will return the "where_at_now" field to it's starting -- position if the_letter is not "" then put 1 into count repeat while count < 6 get line count of card field "active" of card "computer card" if first word of it is the_letter then delete line count of card field "active" of card "computer card" else add 1 to count end if end repeat end if get last line of card field "active" of card "computer card" if it is empty then return false -- ok, we left a ship unsunk, reset the variables -- as if we had just made the last hit on it, -- that is which ship, where and direction, then -- do a quick test to see where the next un-tested -- space around here is. put first word of it into active_ship put second word of it into where_at_now put third word of it into direction get new_direction() -- find out if we've gone this way before. -- if so, keep swinging clockwise put where_at_now + direction into temp if temp > 0 and temp < 65 then get icon of button temp of card "player Card" if opponent is "CVSC" then get icon of button temp of card "Enemy Board" end if if it is not 0 then get new_direction() end if else get new_direction() put where_at_now + direction into temp if temp > 0 and temp < 65 then get icon of button temp of card "player Card" if opponent is "CVSC" then get icon of button temp of card "Enemy Board" end if if it is not 0 then get new_direction() end if else get new_direction() put where_at_now + direction into temp if temp > 0 and temp < 65 then get icon of button temp of card "player Card" if opponent is "CVSC" then get icon of button temp of card "Enemy Board" end if if it is not 0 then get new_direction() end if else get new_direction() return true end done_test -- part 1 (field) -- low flags: 80 -- high flags: 0004 -- rect: left=182 top=22 right=57 bottom=445 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Data -- part 2 (field) -- low flags: 80 -- high flags: 0004 -- rect: left=183 top=59 right=94 bottom=446 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Message -- part 8 (field) -- low flags: 80 -- high flags: 0007 -- rect: left=69 top=23 right=328 bottom=146 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Pattern -- part 11 (field) -- low flags: 80 -- high flags: 0004 -- rect: left=308 top=185 right=287 bottom=506 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Active -- part 12 (field) -- low flags: 01 -- high flags: 0002 -- rect: left=192 top=183 right=264 bottom=320 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: status -- part 13 (field) -- low flags: 80 -- high flags: 0007 -- rect: left=18 top=31 right=188 bottom=496 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: lines -- part contents for card part 8 ----- text ----- 57 53 42 38 27 23 12 8 33 29 18 14 3 63 52 48 9 5 58 54 43 39 28 24 49 45 34 30 19 15 4 64 25 21 10 6 59 55 44 40 1 61 50 46 35 31 20 16 41 37 26 22 11 7 60 56 17 13 2 62 51 47 36 32 -- part contents for card part 12 ----- text ----- Battle Ship Carrier Transport Submarine PT Boat -- part contents for card part 13 ----- text ----- Ahh.. you Don't have Chance I have not yet begun to fight! Talking to a Computer even... A door is Ajar That does not compute. Why don't you go out and get some real friends? Warning! Warning! Warning! I Cheat! Hello, My name is Ralph. I'm Sorry, that number is no longer in Service I'm Sorry, The Computer is Out. Stay Tuned to this Channel. Stop Talking and get on with it. -- part contents for background part 51 ----- text ----- B -- part contents for background part 52 ----- text ----- B -- part contents for background part 53 ----- text ----- B -- part contents for background part 54 ----- text ----- B -- part contents for background part 55 ----- text ----- B -- part contents for background part 12 ----- text ----- C -- part contents for background part 13 ----- text ----- C -- part contents for background part 14 ----- text ----- C -- part contents for background part 15 ----- text ----- C -- part contents for background part 42 ----- text ----- T -- part contents for background part 50 ----- text ----- T -- part contents for background part 58 ----- text ----- T -- part contents for background part 27 ----- text ----- S -- part contents for background part 28 ----- text ----- S -- part contents for background part 29 ----- text ----- S -- part contents for background part 57 ----- text ----- P -- part contents for background part 65 ----- text ----- P